home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
playerselect.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
12KB
|
532 lines
#include "stdafx.h"
#include <process.h>
#include "PlayerSelect.h"
CPlayerSelect::CPlayerSelect(CWnd* pParent)
: CDialog(CPlayerSelect::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlayerSelect)
m_Pl1Selected = FALSE;
m_Pl1Name = _T("");
m_Pl2Selected = FALSE;
m_Pl2Name = _T("");
m_Pl3Selected = FALSE;
m_Pl3Name = _T("");
m_Pl4Selected = FALSE;
m_Pl4Name = _T("");
m_Pl5Selected = FALSE;
m_Pl5Name = _T("");
m_Pl6Selected = FALSE;
m_Pl6Name = _T("");
m_Pl7Selected = FALSE;
m_Pl7Name = _T("");
m_Pl8Selected = FALSE;
m_Pl8Name = _T("");
//}}AFX_DATA_INIT
// Set names
m_Pl1Name = pl_name[0];
m_Pl2Name = pl_name[1];
m_Pl3Name = pl_name[2];
m_Pl4Name = pl_name[3];
m_Pl5Name = pl_name[4];
m_Pl6Name = pl_name[5];
m_Pl7Name = pl_name[6];
m_Pl8Name = pl_name[7];
// Set selected
m_Pl1Selected = pl_selected[0];
m_Pl2Selected = pl_selected[1];
m_Pl3Selected = pl_selected[2];
m_Pl4Selected = pl_selected[3];
m_Pl5Selected = pl_selected[4];
m_Pl6Selected = pl_selected[5];
m_Pl7Selected = pl_selected[6];
m_Pl8Selected = pl_selected[7];
}
CPlayerSelect::~CPlayerSelect()
{
}
void CPlayerSelect::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlayerSelect)
DDX_Check(pDX, IDC_PL1CHECK, m_Pl1Selected);
DDX_Text(pDX, IDC_PL1NAME, m_Pl1Name);
DDV_MaxChars(pDX, m_Pl1Name, 15);
DDX_Check(pDX, IDC_PL2CHECK, m_Pl2Selected);
DDX_Text(pDX, IDC_PL2NAME, m_Pl2Name);
DDV_MaxChars(pDX, m_Pl2Name, 15);
DDX_Check(pDX, IDC_PL3CHECK, m_Pl3Selected);
DDX_Text(pDX, IDC_PL3NAME, m_Pl3Name);
DDV_MaxChars(pDX, m_Pl3Name, 15);
DDX_Check(pDX, IDC_PL4CHECK, m_Pl4Selected);
DDX_Text(pDX, IDC_PL4NAME, m_Pl4Name);
DDV_MaxChars(pDX, m_Pl4Name, 15);
DDX_Check(pDX, IDC_PL5CHECK, m_Pl5Selected);
DDX_Text(pDX, IDC_PL5NAME, m_Pl5Name);
DDV_MaxChars(pDX, m_Pl5Name, 15);
DDX_Check(pDX, IDC_PL6CHECK, m_Pl6Selected);
DDX_Text(pDX, IDC_PL6NAME, m_Pl6Name);
DDV_MaxChars(pDX, m_Pl6Name, 15);
DDX_Check(pDX, IDC_PL7CHECK, m_Pl7Selected);
DDX_Text(pDX, IDC_PL7NAME, m_Pl7Name);
DDV_MaxChars(pDX, m_Pl7Name, 15);
DDX_Check(pDX, IDC_PL8CHECK, m_Pl8Selected);
DDX_Text(pDX, IDC_PL8NAME, m_Pl8Name);
DDV_MaxChars(pDX, m_Pl8Name, 15);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlayerSelect, CDialog)
//{{AFX_MSG_MAP(CPlayerSelect)
ON_BN_CLICKED(IDC_PL4CONFIGURE, OnPl4Configure)
ON_BN_CLICKED(IDC_PL1CONFIGURE, OnPl1Configure)
ON_BN_CLICKED(IDC_PL2CONFIGURE, OnPl2Configure)
ON_BN_CLICKED(IDC_PL3CONFIGURE, OnPl3Configure)
ON_BN_CLICKED(IDC_PL5CONFIGURE, OnPl5Configure)
ON_BN_CLICKED(IDC_PL6CONFIGURE, OnPl6Configure)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_PL7CONFIGURE, OnPl7Configure)
ON_BN_CLICKED(IDC_PL8CONFIGURE, OnPl8Configure)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CPlayerSelect::OnDestroy()
{
CDialog::OnDestroy();
// Save names
strcpy(pl_name[0], m_Pl1Name);
strcpy(pl_name[1], m_Pl2Name);
strcpy(pl_name[2], m_Pl3Name);
strcpy(pl_name[3], m_Pl4Name);
strcpy(pl_name[4], m_Pl5Name);
strcpy(pl_name[5], m_Pl6Name);
strcpy(pl_name[6], m_Pl7Name);
strcpy(pl_name[7], m_Pl8Name);
// Save selected
pl_selected[0] = m_Pl1Selected;
pl_selected[1] = m_Pl2Selected;
pl_selected[2] = m_Pl3Selected;
pl_selected[3] = m_Pl4Selected;
pl_selected[4] = m_Pl5Selected;
pl_selected[5] = m_Pl6Selected;
pl_selected[6] = m_Pl7Selected;
pl_selected[7] = m_Pl8Selected;
}
void CPlayerSelect::OnPl1Configure()
{
CKeySetup k(0);
k.DoModal();
}
void CPlayerSelect::OnPl2Configure()
{
CKeySetup k(1);
k.DoModal();
}
void CPlayerSelect::OnPl3Configure()
{
CKeySetup k(2);
k.DoModal();
}
void CPlayerSelect::OnPl4Configure()
{
CMouseSetup m;
m.DoModal();
}
void CPlayerSelect::OnPl5Configure()
{
CJoySetup j(0);
j.DoModal();
}
void CPlayerSelect::OnPl6Configure()
{
CJoySetup j(1);
j.DoModal();
}
void CPlayerSelect::OnPl7Configure()
{
CJoySetup j(2);
j.DoModal();
}
void CPlayerSelect::OnPl8Configure()
{
CJoySetup j(3);
j.DoModal();
}
CKeySetup::CKeySetup(int _n, CWnd* pParent)
: CDialog(CKeySetup::IDD, pParent)
{
//{{AFX_DATA_INIT(CKeySetup)
//}}AFX_DATA_INIT
n = _n;
}
void CKeySetup::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeySetup)
DDX_Control(pDX, IDC_KEY_UP, m_Up);
DDX_Control(pDX, IDC_KEY_RIGHT, m_Right);
DDX_Control(pDX, IDC_KEY_LEFT, m_Left);
DDX_Control(pDX, IDC_KEY_FIRE, m_Fire);
DDX_Control(pDX, IDC_KEY_DOWN, m_Down);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKeySetup, CDialog)
//{{AFX_MSG_MAP(CKeySetup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CKeySetup::OnInitDialog()
{
LPDIRECTINPUTDEVICE2 keyboard;
DIDEVICEOBJECTINSTANCE didoi;
int idx;
CDialog::OnInitDialog();
// Clear combo boxes
m_Left.ResetContent();
m_Right.ResetContent();
m_Up.ResetContent();
m_Down.ResetContent();
m_Fire.ResetContent();
// Fill combo boxes with available buttons
keyboard = create_input_device_keyboard();
didoi.dwSize = sizeof(didoi);
for (DWORD dwOfs = 0; dwOfs < 256; dwOfs++)
if (SUCCEEDED(keyboard->GetObjectInfo(&didoi, dwOfs, DIPH_BYOFFSET)))
{
// Add button to Left list
idx = m_Left.AddString(didoi.tszName);
m_Left.SetItemData(idx, dwOfs);
if (key_left[n] == dwOfs)
m_Left.SetCurSel(idx);
// Add button to Right list
idx = m_Right.AddString(didoi.tszName);
m_Right.SetItemData(idx, dwOfs);
if (key_right[n] == dwOfs)
m_Right.SetCurSel(idx);
// Add button to Up list
idx = m_Up.AddString(didoi.tszName);
m_Up.SetItemData(idx, dwOfs);
if (key_up[n] == dwOfs)
m_Up.SetCurSel(idx);
// Add button to Down list
idx = m_Down.AddString(didoi.tszName);
m_Down.SetItemData(idx, dwOfs);
if (key_down[n] == dwOfs)
m_Down.SetCurSel(idx);
// Add button to Fire list
idx = m_Fire.AddString(didoi.tszName);
m_Fire.SetItemData(idx, dwOfs);
if (key_fire[n] == dwOfs)
m_Fire.SetCurSel(idx);
}
keyboard->Release();
return TRUE;
}
void CKeySetup::OnOK()
{
key_left[n] = m_Left.GetItemData(m_Left.GetCurSel());
key_right[n] = m_Right.GetItemData(m_Right.GetCurSel());
key_up[n] = m_Up.GetItemData(m_Up.GetCurSel());
key_down[n] = m_Down.GetItemData(m_Down.GetCurSel());
key_fire[n] = m_Fire.GetItemData(m_Fire.GetCurSel());
CDialog::OnOK();
}
CMouseSetup::CMouseSetup(CWnd* pParent)
: CDialog(CMouseSetup::IDD, pParent)
{
//{{AFX_DATA_INIT(CMouseSetup)
//}}AFX_DATA_INIT
}
void CMouseSetup::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMouseSetup)
DDX_Control(pDX, IDC_MOUSE_REVERSE, m_Reverse);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMouseSetup, CDialog)
//{{AFX_MSG_MAP(CMouseSetup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CMouseSetup::OnInitDialog()
{
CDialog::OnInitDialog();
m_Reverse.SetCheck(reverse_mouse);
return TRUE;
}
void CMouseSetup::OnOK()
{
reverse_mouse = m_Reverse.GetCheck();
CDialog::OnOK();
}
CJoySetup::CJoySetup(int _n, CWnd* pParent)
: CDialog(CJoySetup::IDD, pParent)
{
//{{AFX_DATA_INIT(CJoySetup)
//}}AFX_DATA_INIT
n = _n;
fire = joy_fire[n];
jetpack = joy_jetpack[n];
mine = joy_mine[n];
}
void CJoySetup::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJoySetup)
DDX_Control(pDX, IDC_JOY_MINE, m_Mine);
DDX_Control(pDX, IDC_JOY_JETPACK, m_Jetpack);
DDX_Control(pDX, IDC_JOY_FIRE, m_Fire);
DDX_Control(pDX, IDC_JOY_DEVICE, m_Device);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJoySetup, CDialog)
//{{AFX_MSG_MAP(CJoySetup)
ON_BN_CLICKED(IDC_CALIBRATE_JOYSTICK, OnCalibrateJoystick)
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_JOY_DEVICE, OnSelchangeJoyDevice)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CJoySetup::OnCalibrateJoystick()
{
_spawnlp(_P_NOWAIT, "CONTROL", "CONTROL", "JOY.CPL", 0);
}
static BOOL CALLBACK DIEnumDevicesProc(LPCDIDEVICEINSTANCE lpddi, LPVOID _joysetup)
{
CJoySetup *joysetup = (CJoySetup *)_joysetup;
// Add string to combobox
int idx = joysetup->m_Device.AddString(lpddi->tszInstanceName);
// Allocate new GUID
GUID *g = new GUID(lpddi->guidInstance);
// Associate GUID with device in combobox
joysetup->m_Device.SetItemDataPtr(idx, g);
return DIENUM_CONTINUE;
}
BOOL CJoySetup::OnInitDialog()
{
CDialog::OnInitDialog();
// Add option none
m_Device.SetItemDataPtr(m_Device.AddString(SELECTION_NONE), (LPVOID)0xffffffff);
// Get attached joysticks
DI->EnumDevices(DIDEVTYPE_JOYSTICK, DIEnumDevicesProc, this, DIEDFL_ATTACHEDONLY);
// Select one or select default
m_Device.SelectString(0, joy_str[n]);
if (m_Device.GetCurSel() == -1)
m_Device.SelectString(0, SELECTION_NONE);
// Populate the lists for buttons
PopulateButtonList();
return TRUE;
}
void CJoySetup::PopulateButtonList()
{
LPDIRECTINPUTDEVICE2 joystick;
DIDEVICEOBJECTINSTANCE didoi;
int idx;
// Reset combo boxes
m_Fire.ResetContent();
m_Jetpack.ResetContent();
m_Mine.ResetContent();
// Get GUID of joystick
GUID *g = (GUID *)m_Device.GetItemDataPtr(m_Device.GetCurSel());
if (g == (GUID *)0xffffffff)
return;
// Fill boxes with available buttons
joystick = create_input_device_joystick(g);
didoi.dwSize = sizeof(didoi);
for (int b = 0; b < 32; b++)
{
DWORD dwOfs = DIJOFS_BUTTON(b);
if (SUCCEEDED(joystick->GetObjectInfo(&didoi, dwOfs, DIPH_BYOFFSET)))
{
// Add button to Fire list
idx = m_Fire.AddString(didoi.tszName);
m_Fire.SetItemData(idx, dwOfs);
if (fire == dwOfs)
m_Fire.SetCurSel(idx);
// Add button to Jetpack list
idx = m_Jetpack.AddString(didoi.tszName);
m_Jetpack.SetItemData(idx, dwOfs);
if (jetpack == dwOfs)
m_Jetpack.SetCurSel(idx);
// Add button to Mine list
idx = m_Mine.AddString(didoi.tszName);
m_Mine.SetItemData(idx, dwOfs);
if (mine == dwOfs)
m_Mine.SetCurSel(idx);
}
}
joystick->Release();
// Mine button is not required
m_Mine.SetItemData(m_Mine.AddString(SELECTION_NONE), -1);
// Make sure something is selected for Mine
if (m_Mine.GetCurSel() == -1)
m_Mine.SelectString(0, SELECTION_NONE);
}
void CJoySetup::OnDestroy()
{
CDialog::OnDestroy();
// Delete allocated GUID's
for (int idx = m_Device.GetCount() - 1; idx >= 0; idx--)
if (m_Device.GetItemDataPtr(idx) != (LPVOID)0xffffffff)
delete (GUID *)m_Device.GetItemDataPtr(idx);
}
void CJoySetup::OnSelchangeJoyDevice()
{
fire = DIJOFS_BUTTON0;
jetpack = DIJOFS_BUTTON1;
mine = DIJOFS_BUTTON2;
PopulateButtonList();
}
void CJoySetup::OnOK()
{
CDialog::OnOK();
// Delete old GUID
safe_delete(&joy_guid[n]);
// Check if anything was selected
GUID *g = (GUID *)m_Device.GetItemDataPtr(m_Device.GetCurSel());
if (g == (GUID *)0xffffffff)
{
// Select no joystick
strcpy(joy_str[n], "");
joy_guid[n] = 0;
return;
}
// Copy settings
m_Device.GetLBText(m_Device.GetCurSel(), joy_str[n]);
joy_guid[n] = new GUID(*g);
joy_fire[n] = m_Fire.GetItemData(m_Fire.GetCurSel());
joy_jetpack[n] = m_Jetpack.GetItemData(m_Jetpack.GetCurSel());
joy_mine[n] = m_Mine.GetItemData(m_Mine.GetCurSel());
}